package edu.neumont.pro180._2009_q2.chess;

import java.util.Random;

import edu.neumont.pro180._2009_q2.GamePieceMove;
import edu.neumont.pro180._2009_q2.Player;
import edu.neumont.pro180._2009_q2.Square;
import edu.neumont.pro180._2009_q2.interfaces.IGamePiece;

public class RandomAIPlayer extends Player {
	private static Random random = new Random();
	@Override 
	public GamePieceMove getNextMove() {
		GamePieceMove move = null;
		IGamePiece[] activePieces = getActivePieces().toArray(new IGamePiece[0]);
		while (move == null) {
			IGamePiece piece = activePieces[random.nextInt(activePieces.length)];
			Square[] moves = piece.getPossibleSquares().toArray(new Square[0]);
			if (moves.length > 0) {
				Square square = moves[random.nextInt(moves.length)];
				move = piece.getMove(square);
			}
		}
		return move;
	}
}
